package com.example.myc

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.TextView

class MainActivity : AppCompatActivity() {

    var index = 9

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val left = findViewById<TextView>(R.id.tv_left)
        val center = findViewById<TextView>(R.id.tv_center)
        val right = findViewById<TextView>(R.id.tv_right)

        left.setOnClickListener {
            if (index != 0) {
                index -= 1
                center.text = index.toString()
                setValue()
            }
        }
        right.setOnClickListener {
            if (index != 13) {
                index += 1
                center.text = index.toString()
                setValue()
            }
        }

        // 默认值
        center.text = index.toString()
        setValue()
    }

    fun setValue() {
        findViewById<View>(R.id.in_0).visibility = View.GONE
        findViewById<View>(R.id.in_1).visibility = View.GONE
        findViewById<View>(R.id.in_2).visibility = View.GONE
        findViewById<View>(R.id.in_3).visibility = View.GONE
        findViewById<View>(R.id.in_4).visibility = View.GONE
        findViewById<View>(R.id.in_5).visibility = View.GONE
        findViewById<View>(R.id.in_6).visibility = View.GONE
        findViewById<View>(R.id.in_7).visibility = View.GONE
        findViewById<View>(R.id.in_8).visibility = View.GONE
        findViewById<View>(R.id.in_9).visibility = View.GONE
        findViewById<View>(R.id.in_10).visibility = View.GONE
        findViewById<View>(R.id.in_11).visibility = View.GONE
        findViewById<View>(R.id.in_12).visibility = View.GONE
        findViewById<View>(R.id.in_13).visibility = View.GONE

        when (index) {
            0 -> findViewById<View>(R.id.in_0).visibility = View.VISIBLE
            1 -> findViewById<View>(R.id.in_1).visibility = View.VISIBLE
            2 -> findViewById<View>(R.id.in_2).visibility = View.VISIBLE
            3 -> findViewById<View>(R.id.in_3).visibility = View.VISIBLE
            4 -> findViewById<View>(R.id.in_4).visibility = View.VISIBLE
            5 -> findViewById<View>(R.id.in_5).visibility = View.VISIBLE
            6 -> findViewById<View>(R.id.in_6).visibility = View.VISIBLE
            7 -> findViewById<View>(R.id.in_7).visibility = View.VISIBLE
            8 -> findViewById<View>(R.id.in_8).visibility = View.VISIBLE
            9 -> findViewById<View>(R.id.in_9).visibility = View.VISIBLE
            10 -> findViewById<View>(R.id.in_10).visibility = View.VISIBLE
            11 -> findViewById<View>(R.id.in_11).visibility = View.VISIBLE
            12 -> findViewById<View>(R.id.in_12).visibility = View.VISIBLE
            13 -> findViewById<View>(R.id.in_13).visibility = View.VISIBLE
        }

    }

}